#define DEBUG
#include <cstdio>

using namespace std;

typedef long long ll;
const int maxn=11, mods=1000000007;

class Matrix {
public:
  const static int maxs=(maxn+1)*(maxn+1)+1;
  int n, m;
  ll v[maxs][maxs];

  void one(int s) {
    n = m = s;
    for (int i=0; i<=n; i++) {
      v[i][i] = 1;
    }
  }

  void mul(Matrix &a, Matrix &b) {
    n = a.n;
    m = b.m;
    for (int i=0; i<=n; i++) {
      for (int j=0; j<=m; j++) {
        v[i][j] = 0;
        for (int k=0; k<=a.m; k++) {
          v[i][j] = (v[i][j]+a.v[i][k]*b.v[k][j]%mods)%mods;
        }
      }
    }
  }

  void qpower(Matrix &a, int n) {
    static Matrix temp[2][2];
    temp[1][0].one(a.n);
    temp[0][0] = a;
    int i=0, j=0;
    for (; n; n>>=1) {
      if (n&1) {
        temp[1][!j].mul(temp[0][i], temp[1][j]);
        j = !j;
      }
      temp[0][!i].mul(temp[0][i], temp[0][i]);
      i = !i;
    }
    *this=temp[1][j];
  }
};

void makeMatrix(int n, Matrix &m) {
  m.n = m.m = 12*12;
  m.v[0][12*12] = 1;
  m.v[12*12][12*12] = 1;
  for (int i=0; i<=n; i++) {
    for (int j=0; j<=n-i; j++) {
      //n-i-j:0, i:1, j:2;
      if (j>0) {
        m.v[i*12+j][(i+1)*12+j-1] = j;
      }
      if (i>0) {
        m.v[i*12+j][(i-1)*12+j] = i;
      }
      if (n-i-j>0) {
        m.v[i*12+j][i*12+j+1] = n-i-j;
      }
    }
  }
}

int main() {
#ifdef DEBUG
  freopen("src.in", "r", stdin);
  freopen("src.out", "w", stdout);
#endif

  static char s[maxn+1], t[maxn+1];
  static int cost[3], time[3];
  int maxc, len;
  scanf("%s %s %d %d %d %d", s, t, cost, cost+1, cost+2, &maxc);
  for (int i=0; s[i]; i++) {
    if (t[i]) {
      time[(t[i]-s[i]+3)%3]++;
      for (int j=(s[i]-'a')%3; 'a'+j!=t[i]; j=(j+1)%3) {
        maxc-=cost[j];
      }
    } else {
      printf("0");
      return 0;
    }
    len = i+1;
  }

  int times=3*(maxc/(cost[0]+cost[1]+cost[2]))+time[1]+time[2]*2;
  static Matrix tem, trans, ans, first;
  makeMatrix(len, tem);
  first.n = 0, first.m=12*12;
  first.v[0][time[1]*12+time[2]] = 1;
  trans.qpower(tem, times);
  ans.mul(first, trans);
  printf("%lld", (ans.v[0][12*12]+ans.v[0][0])%mods);

  fclose(stdin);
  fclose(stdout);
  return 0;
}
